package 公司真题.字节跳动;


import java.util.Scanner;

public class _万万没想到之聪明的编辑 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());
        if (num == 0) return;
        while (sc.hasNextLine()) {
            String text = sc.nextLine();
            char[] arr = text.toCharArray();

            Character[] Carr = new Character[arr.length];
            for (int i = 0; i < arr.length; i++) {
                Carr[i] = arr[i];
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < Carr.length; i++) {
                if (AAA(Carr, i)) {
                    Carr[i] = null;
                }
                if (AABB(Carr, i)) {
                    Carr[i] = null;
                }
                if (Carr[i] != null) {
                    sb.append(Carr[i]);
                }
            }
            System.out.println(sb.toString());
        }
    }

    private static boolean AAA(Character[] carr, int index) {
        if (index < 2) return false;
        int count = 1;
        for (int i = index - 1; i >= 0; i--) {
            if (carr[i] == null) continue;
            if (carr[i] != carr[index]) return false;
            count++;
            if (count == 3) return true;
        }
        return false;
    }

    private static boolean AABB(Character[] carr, int indexB) {
        if (indexB < 3) return false;
        int countOne = 1;
        // 检测BB
        boolean flagB = false;
        int indexA = indexB;
        for (int i = indexB - 1; i >= 0; i--) {
            if (carr[i] == null) continue;
            if (carr[i] != carr[indexB]) return false;
            countOne++;
            if (countOne == 2) {
                flagB = true;
                indexA = i;
                break;
            }
        }
        if (!flagB) return false;
        // 找到AA
        indexA -= 1;
        while (indexA >= 0 && carr[indexA] == null) {
            indexA--;
        }
        if (indexA < 0) return false;
        char A = carr[indexA];
        int countTwo = 1;
        boolean flagA = false;
        for (int i = indexA - 1; i >= 0; i--) {
            if (carr[i] == null) continue;
            if (carr[i] != A) return false;
            countTwo++;
            if (countTwo == 2) {
                flagA = true;
                break;
            }
        }
        return flagA && flagB;
    }
}
